// d:\project\honey-Alliance-project\shenye-dy-applet\components\password-box\password-box.js
Component({
  data: {
    password: '', //交易密码
    numberBox: [{
      id: 1,
      num: '1'
    },
    {
      id: 2,
      num: '2'
    },
    {
      id: 3,
      num: '3'
    },
    {
      id: 4,
      num: '4'
    },
    {
      id: 5,
      num: '5'
    },
    {
      id: 6,
      num: '6'
    },
    {
      id: 7,
      num: '7'
    },
    {
      id: 8,
      num: '8'
    },
    {
      id: 9,
      num: '9'
    },
    {
      id: 10,
      num: ''
    },
    {
      id: 11,
      num: '0'
    },
    {
      id: 12,
      num: ''
    },
    ],
    title: '请输入交易密码',
    titleHint: '您使用了神椰数字资产请进行验证',
  },
  properties: {
    title: {
      type: String,
      value: '请输入交易密码'
    },
    titleHint: {
      type: String,
      value: '您使用了神椰数字资产请进行验证'
    },
  },
  methods: {
    // 关闭密码框
    closePassword() {
      this.close('passwordPopup')
      this.triggerEvent('confirm')
    },
    clearPassword() {
      this.setData({
        password: ''
      })
    },
    // 点击密码操作
    clickNum(e) {
      var item = e.currentTarget.dataset.item
      if (this.data.password.length < 6) {
        this.data.password += item.num
        this.setData({
          password: this.data.password
        })
        if (this.data.password.length === 6) {
          this.triggerEvent('confirmPassword', {
            password: this.data.password
          })
        }
      }

    },
    //密码输入删除
    deleteNum(e) {
      if (this.data.password.length > 0) {
        this.data.password = this.data.password.substring(0, this.data.password.length - 1)
        this.setData({
          password: this.data.password
        })
      }
    },
    openPopup() {
      this.clearPassword()
      this.open('passwordPopup')
    },
    closePopup() {
      this.close('passwordPopup')
    },
    // 取消
    cancel() {
      this.close('passwordPopup')
      this.triggerEvent('cancel')
    },
    // // 确认
    // confirm(){
    //   this.close('passwordPopup')
    //   this.triggerEvent('confirm')
    // },
    // 打开弹窗
    open(popupName) {
      const childComponent = this.selectComponent('#' + popupName);
      childComponent.open();
    },
    // 关闭弹窗
    close(popupName) {
      const childComponent = this.selectComponent('#' + popupName);
      childComponent.close();
    },
  }
})